//
//  XLRegisterFinishView.m
//  industry
//
//  Created by xl on 2020/11/20.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLRegisterFinishView.h"
#import "XLLoginModel.h"
#import "XLLoginRegisterVC.h"
#import "XLLoginRegisterPresenterProtocol.h"

@interface XLRegisterFinishView ()

@property (nonatomic, strong) XLButton *backBtn;
@property (nonatomic, strong) XLLabel *titleLB;
@property (nonatomic, strong) XLImageView *circleBgIG;
@property (nonatomic, strong) XLLabel *adLB;
@property (nonatomic, strong) XLView *adLeftLineView;
@property (nonatomic, strong) XLView *adRightLineView;
@property (nonatomic, strong) XLLabel *accountLB;
@property (nonatomic, strong) XLTextField *accountTF;
@property (nonatomic, strong) XLView *accountLineView;
@property (nonatomic, strong) XLLabel *passwordLB;
@property (nonatomic, strong) XLTextField *passwordTF;
@property (nonatomic, strong) XLView *passwordLineView;
@property (nonatomic, strong) XLButton *finshBtn;

@end
@implementation XLRegisterFinishView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteBgColor];
        UIBezierPath *cornerRaduisPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(50, 50)];
        CAShapeLayer *cornerRadiusLayer = [[CAShapeLayer alloc] init];
        cornerRadiusLayer.frame = self.bounds;
        cornerRadiusLayer.path = cornerRaduisPath.CGPath;
        self.layer.mask = cornerRadiusLayer;
        
        [self addSubview:self.backBtn];
        [self addSubview:self.titleLB];
        [self addSubview:self.circleBgIG];
        [self addSubview:self.adLB];
        [self addSubview:self.adLeftLineView];
        [self addSubview:self.adRightLineView];
        
        [self addSubview:self.accountLB];
        [self addSubview:self.accountTF];
        [self addSubview:self.accountLineView];
        [self addSubview:self.passwordLB];
        [self addSubview:self.passwordTF];
        [self addSubview:self.passwordLineView];
        [self addSubview:self.finshBtn];
        
        [self makeConstraints];
    }
    return self;
}

#pragma mark - UIButton 点击事件
- (void)clickGoBack {
    [self.baseController.navigationController popViewControllerAnimated:YES];
}

- (void)clickFinish {
    if (ISEmptyString(_accountTF.text)) {
        [XLToast showComonMessage:@"请输入新密码"];
        return;
    }
    if (ISEmptyString(_passwordTF.text)) {
        [XLToast showComonMessage:@"请再次输入新密码"];
        return;
    }
    
    if (![_accountTF.text isEqualToString:_passwordTF.text]) {
        [XLToast showComonMessage:@"前后密码不一致"];
        return;
    }
    XLLoginModel *model = [[XLLoginModel alloc] init];
    model.password = _accountTF.text;
    model.rePassword = _passwordTF.text;
    model.isStafff = [(XLLoginRegisterVC *)self.baseController isStaff];
    model.phone = [(XLLoginRegisterVC *)self.baseController phone];
    XLSend(self.baseController.presenter, XLLoginRegisterPresenterProtocol, requestFetchAESKey:XLFetchAESTypeRegister model:model);
}

#pragma mark - Private
- (void)makeConstraints {
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(self).offset(30);
         make.top.equalTo(self).offset(30);
         make.size.mas_equalTo(CGSizeMake(24, 24));
     }];
     
     [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
         make.right.equalTo(self).offset(-20);
         make.centerY.equalTo(self.backBtn);
     }];
     [_titleLB sizeToFit];
    
     [_circleBgIG mas_makeConstraints:^(MASConstraintMaker *make) {
         make.bottom.right.equalTo(self);
         make.size.mas_equalTo(CGSizeMake(216, 188));
     }];
    
     [_adLB mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerX.equalTo(self);
         make.bottom.equalTo(self).offset(-SAFEAREA_BOTTOM_HEIGHT - 15);
     }];
     [_adLB sizeToFit];
     
     [_adLeftLineView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerY.equalTo(self.adLB);
         make.right.equalTo(self.adLB.mas_left).offset(-10);
         make.left.equalTo(self).offset(26);
         make.height.mas_equalTo(1);
     }];
     
     [_adRightLineView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerY.equalTo(self.adLB);
         make.left.equalTo(self.adLB.mas_right).offset(10);
         make.right.equalTo(self).offset(-26);
         make.height.mas_equalTo(1);
     }];
    
    [_accountLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.top.equalTo(self).offset(70);
    }];
    [_accountLB sizeToFit];
    
    [_accountTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.accountLB);
        make.top.equalTo(self.accountLB.mas_bottom).offset(3);
        make.right.equalTo(self).offset(-30);
        make.height.mas_equalTo(40);
    }];
    
    [_accountLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.accountTF);
        make.top.equalTo(self.accountTF.mas_bottom);
        make.height.mas_equalTo(1);
    }];
    
    [_passwordLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.accountLB);
        make.top.equalTo(self.accountLineView.mas_bottom).offset(5);
    }];
    
    [_passwordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.passwordLB);
        make.top.equalTo(self.passwordLB.mas_bottom).offset(3);
        make.right.equalTo(self).offset(-30);
        make.height.mas_equalTo(40);
    }];
    
    [_passwordLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self).offset(-30);
        make.top.equalTo(self.passwordTF.mas_bottom);
        make.height.mas_equalTo(1);
    }];
    
    [_finshBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self).offset(-30);
        make.top.equalTo(self.passwordLineView.mas_bottom).offset(25);
        make.height.mas_equalTo(45);
    }];
}

#pragma mark - setter/getter
- (XLButton *)backBtn {
    if (!_backBtn) {
        _backBtn = [XLButton new];
        [_backBtn setImage:XLIMAGE(@"back") forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(clickGoBack) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

- (XLLabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [XLLabel new];
        _titleLB.font = [UIFont fontOfPingFangSCSemiboldWithSize:14];
        _titleLB.textColor = [UIColor blackFontColor];
        _titleLB.text = @"";
    }
    return _titleLB;
}

- (XLLabel *)adLB {
    if (!_adLB) {
        _adLB = [XLLabel new];
        _adLB.font = [UIFont fontOfPingFangSCRegularWithSize:11];
        _adLB.textColor = [UIColor grayFontColor];
        _adLB.text = @"为产业而金融，因科技而不同";
    }
    return _adLB;
}

- (XLView *)adLeftLineView {
    if (!_adLeftLineView) {
        _adLeftLineView = [XLView new];
        _adLeftLineView.backgroundColor = [UIColor grayLineColor];
    }
    return _adLeftLineView;
}

- (XLView *)adRightLineView {
    if (!_adRightLineView) {
        _adRightLineView = [XLView new];
        _adRightLineView.backgroundColor = [UIColor grayLineColor];
    }
    return _adRightLineView;
}

- (XLLabel *)accountLB {
    if (!_accountLB) {
        _accountLB = [XLLabel new];
        _accountLB.font = [UIFont fontOfPingFangSCSemiboldWithSize:15];
        _accountLB.textColor = [UIColor blackFontColor];
        _accountLB.text = @"请输入您的密码";
    }
    return _accountLB;
}

- (XLTextField *)accountTF {
    if (!_accountTF) {
        _accountTF = [XLTextField new];
        _accountTF.font = [UIFont fontOfPingFangSCRegularWithSize:16];
        _accountTF.placeholder = @"请输入您的密码";
        _accountTF.tintColor = [UIColor redFontColor];
        _accountTF.textColor = [UIColor blackFontColor];
        _accountTF.keyboardType = UIKeyboardTypeNumberPad;
        _accountTF.enablesReturnKeyAutomatically = YES;
        _accountTF.returnKeyType = UIReturnKeyNext;
        _accountTF.secureTextEntry = YES;
    }
    return _accountTF;
}

- (XLView *)accountLineView {
    if (!_accountLineView) {
        _accountLineView = [XLView new];
        _accountLineView.backgroundColor = [UIColor grayLineColor];
    }
    return _accountLineView;
}

- (XLLabel *)passwordLB {
    if (!_passwordLB) {
        _passwordLB = [XLLabel new];
        _passwordLB.font = [UIFont fontOfPingFangSCSemiboldWithSize:15];
        _passwordLB.textColor = [UIColor blackFontColor];
        _passwordLB.text = @"请确认您的密码";
    }
    return _passwordLB;
}

- (XLTextField *)passwordTF {
    if (!_passwordTF) {
        _passwordTF = [XLTextField new];
        _passwordTF.font = [UIFont fontOfPingFangSCRegularWithSize:16];
        _passwordTF.placeholder = @"请再次输入您的验证码";
        _passwordTF.tintColor = [UIColor redFontColor];
        _passwordTF.textColor = [UIColor blackFontColor];
        _passwordTF.enablesReturnKeyAutomatically = YES;
        _passwordTF.returnKeyType = UIReturnKeyNext;
        _passwordTF.secureTextEntry = YES;
    }
    return _passwordTF;
}

- (XLView *)passwordLineView {
    if (!_passwordLineView) {
        _passwordLineView = [XLView new];
        _passwordLineView.backgroundColor = [UIColor grayLineColor];
    }
    return _passwordLineView;
}

- (XLButton *)finshBtn {
    if (!_finshBtn) {
        _finshBtn = [XLButton new];
        _finshBtn.layer.cornerRadius = 22.5f;
        _finshBtn.layer.masksToBounds = YES;
        _finshBtn.backgroundColor = [UIColor blueBgColor];
        _finshBtn.titleLabel.font = [UIFont fontOfPingFangSCSemiboldWithSize:16];
        [_finshBtn setTitleColor:[UIColor whiteFontColor] forState:UIControlStateNormal];
        [_finshBtn setTitle:@"完成注册" forState:UIControlStateNormal];
        [_finshBtn addTarget:self action:@selector(clickFinish) forControlEvents:UIControlEventTouchUpInside];
    }
    return _finshBtn;
}

- (XLImageView *)circleBgIG {
    if (!_circleBgIG) {
        _circleBgIG = [XLImageView new];
        _circleBgIG.image = XLIMAGE(@"tybg");
    }
    return _circleBgIG;
}

@end
